import Vue from 'vue'
import Vuex from 'vuex'
import { Message } from 'element-ui'
import { m7Language } from '@/utils/m7Utils.js'
import * as actions from './actions'
import * as getters from './getters'
import mutations from './mutations'
// import customer from './modules/customer/'
// import call from './modules/call/'
// import webchat from './modules/webchat/'
// import socketPush from './modules/socket-push'
// import email from './modules/email/'
// import monitor from './modules/monitor'
// import cti from './modules/cti'
// import workbench from './modules/workbench'
// import business from './modules/business'
// import km from './modules/km'
// import sms from './modules/sms'
// import questionnaire from './modules/questionnaire'
// import qualityCheck from './modules/quality-check'
// import report from './modules/report'
// import config from './modules/config'

Vue.use(Vuex)

// const debug = process.env.NODE_ENV !== 'production'

// const 声明 一个常量才不会导致每次刷新会改变 store 的值

const store = new Vuex.Store({
  state: {
    isShowTransCallLibrary: false,
    allKeyLabels: [],
    platform_urls: {
      updateUrl: '',
      restApi: '',
      restApi_https: '',
      ykf: '',
      ykf_https: '',
      ydx: '',
      ydx_https: '',
      platform_type: '',
      webchat: '',
      webchat_https: '',
      showWxHelper: '',
      iosAppUrl: '',
      androidAppUrl: '',
      qhbUrl: ''
    },
    thirdApp: {},
    lang: '',
    iframeNotify: {
      updateVer: {
        updateVer: false,
        updateTime: ''
      },
      notify: {},
      notifyFlag: false
    },
    iframeMessage: {
      loginMessage: {
        loginBg: 'https://fs-test.7moor.com/N00000000143/business/2019-11-25/1574650177156/380dc440-0f2e-11ea-9986-f581cab9785c/%E8%83%8C%E6%99%AF.png',
        loginLeftPhoto: 'https://fs-test.7moor.com/N00000000143/business/2019-11-25/1574650177157/380deb50-0f2e-11ea-9986-f581cab9785c/%E6%8F%92%E7%94%BB.png'
      },
      footerConfig: {
        showWxHelper: '',
        iosAppUrl: '',
        androidAppUrl: ''
      },
      zjkf: {
        url: ''
      }
    },
    // xlsxExportMode: 'End',
    privatization: false,
    isOem: false,
    dateLimit: '',
    isCaptcha: false,    //   是否启用数字验证码
    captchaId: '',    //   获取数字验证码需要的 id
    noticeBusJump: {module: '', random: 0},
    noticeCustJump: {module: '', random: 0},
    noticeWenJump: {module: '', random: 0},
    globalExport: {
      show: false,
      list: []
    },
    verifyShow: false,
    mobileCheckToken: '',
    loading: true,
    login: false,
    labelPosition: 'left',
    ip: false,
    masking: {show: false, type: 'login'},
    serverDiffTime: 0,
    checkedVal: 0,
    pushServerUrl: '',
    attachmentMaxSize: '',
    serverTime: '', // 服务器时间
    dicMapGetterVersion: 0,
    session: {
      dicMap: []
    },
    error: '',
    exit: '',
    success: '',
    info: '',
    softPhoneBar: {},
    phoneBarShow: true,
    multiChannelVoice: true,
    closeAdvSearch: '',
    isPopup: false,
    inviteCon: false,   // 是否展示座席被邀请信息box
    inviteContents: [], // 座席被邀请信息list
    fileDown: {url: '', isSession: ''},
    notify: {},
    isHomePage: false, // 首页对接优化设置的状态
    isCallInterface: {}, // 来电对接优化设置的状态
    isCallOutInterface: {}, // 外呼对接优化设置的状态
    isCallInterfaceButton: {}, // 来电对接弹屏入口的状态
    isCallOutInterfaceButton: {}, // 外呼对接弹屏入口的状态
    curCallSheetId: '', // 来电当前通话Id
    dragPop: {name: '', url: '', token: '', open: false},
    bigCallProcess: {textCode: '', name: '', open: false, processId: ''},
    iframeText: {
      textUrl: '',
      textShow: false
    },
    massMedia: {
      textUrl: '',
      textShow: false,
      flag: ''
    },
    bigImg: {
      imgUrl: '',
      imgShow: false,
      index: 0,
      list: []
    },
    bigOldImg: {
      imgUrl: '',
      imgShow: false
    },
    oemObj: {
      oemFlag: '',
      oemInfo: ''
    },
    dicVersion: [],
    // 用于在线咨询待处理 和 通话  来电模块
    routes: {
      call: null,
      webchat: null
    },
    kickOut: false, // 是否被踢
    ivrSoundTransfer: {}, // 语音库文件类型转换
    isNormalCallConfig: false,
    unBindGateway: '', // 是否绑定网关
    newSkill: '', // 新技能url
    aiExtension: 'https://www.7moor.com/airobot', // ai推广url
    aiExtensionShow: false, // 是否展示ai推广url
    blank: '', // 空白页
    navMenuState: true, // 空白页
    RemoteControl: {
      isRemoteControl: false,
      remoteFrom: '',
      remoteCustSid: '',
      customerSource: ''
    },   // 发起远程控制参数
    isM7RobotOpen: false,    // 是否启用小七机器人
    isNewCardStyle: { // 全局全新的卡片样式
      business: false // 工单模块
    },
    fileDomain: {}, // 七牛文件域名
    isUseQiniu: true, // 是否使用旧的七牛云
    transferNotice: {}, // 转接提示信息
    transferNoConfirmNotice: {} // 没有确定按钮的转接提示信息
  },
  mutations,
  actions,
  getters,
  // modules: {
  //   customer,
  //   call,
  //   webchat,
  //   email,
  //   socketPush,
  //   monitor,
  //   business,
  //   cti,
  //   workbench,
  //   km,
  //   sms,
  //   questionnaire,
  //   report,
  //   qualityCheck
  // },
  // 方便开发时观察的状态的值
  //
  strict: process.env.NODE_ENV !== 'production' && false
})
let errorObj = {name: '', number: 0}
store.subscribe((mutation, state) => {
  // console.log(mutation.type)
  if (mutation.type === 'SET_ERROR') {
    let one = Message({message: m7Language(state.error), type: 'error', duration: 3000, showClose: true})
    if (errorObj.name === state.error) {
      errorObj.number++
    } else {
      errorObj.number = 0
      errorObj.name = ''
    }
    if (errorObj.number > 3) {
      one.close()
    }
    errorObj.name = state.error
  }
  if (mutation.type === 'SET_SUCCESS') {
    Message({message: m7Language(state.success), type: 'success', duration: 3000, showClose: true})
  }
  if (mutation.type === 'SET_INFO') {
    Message({message: m7Language(state.info), type: 'info', duration: 3000, showClose: true})
  }
})
export default store
